
// <copyright file="DynamicToStringHelperAppend.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   This class has some helper methods that will be called by DynamicToStringHelper.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Reflection.Internal
{
    using System.IO;

    /// <summary>
    ///     This class has some helper methods that will be called by DynamicToStringHelper.
    /// </summary>
    internal class DynamicToStringHelperAppend
    {
        #region Methods

        /// <summary>
        /// Writes the object to text writer.
        /// </summary>
        /// <param name="excludeNullValues">
        /// if set to <c>true</c> [exclude null values].
        /// </param>
        /// <param name="dontWritePropertyNames">
        /// if set to <c>true</c> [dont write property names].
        /// </param>
        /// <param name="prefix">
        /// The prefix.
        /// </param>
        /// <param name="separator">
        /// The separator.
        /// </param>
        /// <param name="suffix">
        /// The suffix.
        /// </param>
        /// <param name="propertyName">
        /// Name of the property.
        /// </param>
        /// <param name="propertyValue">
        /// The property value.
        /// </param>
        /// <param name="writer">
        /// The writer.
        /// </param>
        /// <param name="isLastProperty">
        /// if set to <c>true</c> [is last property].
        /// </param>
        internal static void WriteToWriter(bool excludeNullValues, bool dontWritePropertyNames, string prefix, string separator, string suffix, string propertyName, object propertyValue, TextWriter writer, bool isLastProperty)
        {
            if (!(propertyValue == null && excludeNullValues))
            {
                if (prefix != null)
                {
                    writer.Write(prefix);
                }

                if (!dontWritePropertyNames)
                {
                    writer.Write(propertyName);
                    writer.Write(separator);
                }

                if (propertyValue != null)
                {
                    writer.Write(propertyValue.ToString());
                }

                if (!isLastProperty && suffix != null)
                {
                    writer.Write(suffix);
                }
            }
        }

        #endregion Methods
    }
}
